#include <bits/stdc++.h>

using namespace std;

int xx[] = {0 , 0 , -1 , 1};
int yy[] = {1 , -1 , 0 , 0};
int mp[40][40] , hasvis[40][40] , n;
queue <int> x;
queue <int> y;
int main()
{
    cin >> n;
    for(int i = 1 ; i<=n ; i++){
        for(int j=1 ; j<=n ; j++){
            scanf("%d" , &mp[i][j]);
        }
    }
    x.push(0);
    y.push(0);
    hasvis[0][0] = 1;
    while(!x.empty()){
        for(int i = 0 ; i<4 ;i++){
            int dx = x.front()+xx[i];
            int dy = y.front()+yy[i];
            if(mp[dx][dy]==0&&!hasvis[dx][dy]&&dx>=0&&dy>=0&&dx<=n+1&&dy<=n+1){
                hasvis[dx][dy] = 1;
                x.push(dx);
                y.push(dy);
            }
        }
        x.pop();
        y.pop();
    }
    for(int i =1 ;i<=n;i++){
        for(int j=1 ; j<=n ;j++){
            if(!hasvis[i][j]&&mp[i][j]==0)
                cout<<2<<' ';
            else
                cout<<mp[i][j]<<' ';
        }
        cout<<endl;
    }
    return 0;
}
